﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

public partial class Admin_images : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["username"].ToString().Length == 0)
                Response.Redirect("login.aspx");

            lblListImages.Text = layAnhQuangcao();
        }
    }
    protected void butOK_Click(object sender, EventArgs e)
    {
        //tao Filename
        string path = Server.MapPath("../") + "/Quangcao";
        DirectoryInfo dir = new DirectoryInfo(path);

        FileInfo[] files = dir.GetFiles();
        string name = (Convert.ToInt32(files.Length) + 1).ToString();
        //---
        if (FileUploadQuangcao.HasFile)
        {
            path = Server.MapPath("../") + "/Quangcao/" + name + ".jpg";
            FileUploadQuangcao.SaveAs(path);
            lblThongbao.Text = "File Uploaded: " + FileUploadQuangcao.FileName;
            clsImages clsImg = new clsImages();
            clsImg.saveAndResizeImage(path, path, 200, 100, ".jpg");
            
            //Hien hinh vua upload
            lblListImages.Text = layAnhQuangcao();
        }
    }
    protected string layAnhQuangcao()
    {
        string fileList = "";
        string path = Server.MapPath("../") + "/Quangcao";
        DirectoryInfo dir = new DirectoryInfo(path);

        FileInfo[] files = dir.GetFiles();
        foreach (FileInfo file in files)
        {
            fileList = fileList + "<img src='../Quangcao/" + file.Name + "'>";
        }
        return fileList;
    }
}